package core.proto.annotation;

import core.proto.Util;
import static app.constants.CollabVizConstants.*;

/**
 * 
 * @author Wei
 *
 */
public class DocAnnotationModel extends AnnotationModel {

	private int startIndex; 
	private int endIndex;
	private String annotatedText;
	private int x;
	private int y;

	public DocAnnotationModel(int startIndex, int endIndex, 
			String annotatedText, String userText, String docKey, 
			double x, double y){
		
		super(userText, docKey, AnnotationLocation.DOC);
		
		this.startIndex = startIndex;
		this.endIndex = endIndex;
		this.annotatedText = annotatedText;
		this.x = (int) x;
		this.y = (int) y;
	}
	
	@Override
	public String toSaveString() {
		String base = super.toSaveString();
		String custom = Util.joinString(ANNOTATION_DELIMITER, 
				startIndex, 
				endIndex, 
				this.stripMetaCharacters(annotatedText),
				this.x, 
				this.y);
		return String.format("%s%s%s", base, ANNOTATION_DELIMITER, custom) + "<END>";
	}
	
	public DocAnnotationModel(String[] tokens) {
		super(tokens);
		try{
			this.startIndex = Integer.valueOf(tokens[3]);
			this.endIndex = Integer.valueOf(tokens[4]);
			this.annotatedText = this.restoreNewlines(tokens[5]);
			this.x = Integer.valueOf(tokens[6]);
			this.y = Integer.valueOf(tokens[7]);
		}
		catch(ArrayIndexOutOfBoundsException e){
			
		}
	}
	
	public int getX() {
		return x;
	}
	public void setX(int x) {
		this.x = x;
	}
	public int getY() {
		return y;
	}
	public void setY(int y) {
		this.y = y;
	}	
	public int getStartIndex() {
		return startIndex;
	}
	
	public void setStartIndex(int startIndex) {
		this.startIndex = startIndex;
	}
	
	public int getEndIndex() {
		return endIndex;
	}
	
	public void setEndIndex(int endIndex) {
		this.endIndex = endIndex;
	}
	
	public String getAnnotatedText() {
		return annotatedText;
	}
	
	public void setAnnotatedText(String annotatedText) {
		this.annotatedText = annotatedText;
	}
	

}
